package com.qr.mp.injectors;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;

/**
 * 将我们的自定义的方法加入到MybatisPlus这个框架中
 *      FindAll extends AbstractMethod
 *      MySqlInuectors extends AbstractSqlInjector
 *          这个方法中返回对象是一个List<AbstractMethod>
 *
 */
public class FindAll extends AbstractMethod
{
    /**
     * 这个方法会将我们的sql加入到我们的statement中
     * @param mapperClass
     * @param modelClass
     * @param tableInfo
     * @return
     */
    @Override
    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {

        String sqlMethod = "findAll";
        String sql = "select * from " + tableInfo.getTableName();
        SqlSource sqlSource = languageDriver.createSqlSource(configuration, sql, modelClass);
        return this.addSelectMappedStatement(mapperClass, sqlMethod, sqlSource, modelClass, tableInfo);
    }
}
